<template>
  <div>
    <Spin :spinning="loading" tip="Loading...">
      <div style="padding-top: 1rem"></div>
    <!-- table -->
    <!-- 经销商配件管理费率维护及工时系数维护 - 特殊配件管理费率编辑 -->
    <FormPanel ref="formPanel1" :list="formList" :cols="1" :formType="'edit'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
    <div style="margin-bottom: 1rem"></div>
    <template slot="controls" slot-scope="props">
      <multiuse-button size="small" type="primary" icon="el-icon-plus" @click="edit()">添加</multiuse-button>
    </template>
    <div style="padding-top: 1rem"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right',
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()">保 存</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
    <BaseDialog :visible.sync="visible" :title="dialogTitle" destroyOnClose width="850px" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <DealerList @close="close" @save="save"></DealerList>
    </BaseDialog>
    </Spin>
  </div>
</template>
<script>
import { copyUpdateData } from '@/utils/index';
import DealerList from '@/pages/claimDemage/tools/DealerList.vue';
import { editSave, selectById } from '@/api/claim/factory/PartType/index.js';
import { selectByParaCode, multiples } from '@/api/claim/factory/SystemParameterMaintain';
export default {
  // mixins: [dictionary],
  props: ['type', 'rowData'],
  components: {
    DealerList,
  },
  data() {
    return {
      loading: false,
      dialogTitle: '选择经销商',
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      // topFilterInit: this.topFilterInitFun(),
      selectedRows: [], //选中经销商
      formList: this.createFormList(),
      saveData: null,
      newVar: {}
    };
  },
  created() {
    this.chuqi();
  },
  mounted() {
    this.init();
  },
  methods: {
    async chuqi() {
    },
    async multiple(val) {
      this.formList.find((x) => x.fieldName == 'labPrice').initialValue = parseFloat(((val / 100) * this.para1).toFixed(2));
    },
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = val;
      console.log(val);
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    async init() {
      this.loading = true;
      let newVar = await selectById(this.rowData.id);
      this.formList.forEach((x) => {
        console.log(newVar);
        x.initialValue = newVar.data[x.fieldName];
      });
      this.newVar = newVar.data;
      this.loading = false;
    },
    //保存
    async saveDialog() {
      this.$refs.formPanel1.SUBMIT_FORM();
      if (this.saveData !== null) {
        console.log(this.saveData);
        this.newVar = copyUpdateData(this.newVar,this.saveData);
        this.loading = true;
        let res = await editSave(this.newVar);
        console.log(res);
        if (res.resultCode === 200) {
          this.$emit('save');
          return this.$notify.success({ title: '提示信息', message: '保存成功' });
        } else {
          this.loading = false;
          // this.$notify.error({title: '提示信息', message: res.errMsg || '保存失败!' });
          // this.closeDialog();
        }
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    chooseOrderNo() {
      this.visible = true;
    },
    close() {
      this.visible = false;
    },
    save(obj) {
      this.formList.find((x) => x.fieldName == 'dealerCode').initialValue = obj[0].dealerCode;
      this.formList.find((x) => x.fieldName == 'dealerName').initialValue = obj[0].dealerName;
      this.visible = false;
    },
    edit() {},
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '类型代码',
          fieldName: 'code',
          placeholder: '请输入...',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '类型名称',
          fieldName: 'name',
          placeholder: '请输入...',
          // disabled: true,
          rules: [{ required: true, message: '请输入...', trigger: 'change' }]
        },
      ];
    },
  },
};
</script>

<style lang="less" scoped></style>
